
from sqlalchemy import Column, String, Integer, Text, DateTime, ForeignKey, SmallInteger
from sqlalchemy.orm import relationship

from config.mysql_config import Base
from datetime import datetime


class Slide(Base):
    """幻灯片表"""
    __tablename__ = 'slide'

    slide_id = Column(Integer, primary_key=True, autoincrement=True)
    slide_index = Column(Integer, nullable=False)
    slide_image_path = Column(String(500))
    slide_audio_path = Column(String(500))
    slide_audio_duration = Column(Integer)
    text = Column(Text)
    ppt_id = Column(Integer, ForeignKey('ppt.ppt_id', ondelete='CASCADE'), nullable=False)
    del_flag = Column(SmallInteger, default=0)

    # 反向引用：slide.ppt 可访问所属PPT对象
    ppt = relationship('PPT', back_populates='slides')

    def __repr__(self):
        return f"<Slide(slide_id={self.slide_id}, slide_index={self.slide_index}, ppt_id={self.ppt_id})>"

    def to_dict(self):
        return {
            "slide_id": self.slide_id,
            "slide_index": self.slide_index,
            "slide_image_path": self.slide_image_path,
            "slide_audio_path": self.slide_audio_path,
            "slide_audio_duration": self.slide_audio_duration,
            "text": self.text,
            "ppt_id": self.ppt_id,
            "del_flag": self.del_flag
        }
